program chapter6_3
    implicit none
    real r1,c1,r2,c2,l2,r3,l3,r4,c4
    complex i,iwantz,phase
    complex z1,z2,z3,z4
    real omega,u
    u=220

    omega=314
    r1=1
    c1=0.1
    r2=2
    c2=0.01
    l2=0.1
    r3=4
    l3=0.1
    r4=10
    c4=0.01

    z1=cmplx(r1,-1/(omega*c1))
    z2=cmplx(r2,l2*omega-1/(omega*c2))
    z3=cmplx(r3,omega*l3)
    z4=cmplx(r4,-1/(c4*omega))
    i=cmplx(u,0)/iwantz(z1,z2,z3,z4)
    print *, 'z in total=',iwantz(z1,z2,z3,z4)
    print *, 'I in total=', i,'phase=',phase(i)

end program

complex function iwantz(z1,z2,z3,z4)
    complex z1,z2,z3,z4
    complex z34,z234,z1234
    z34=(z3*z4)/(z3+z4)
    z234=z2+z34
    z1234=(z1*z234)/(z1+z234)
    iwantz=z1234
end function

complex function phase(z)
    complex z
    phase=57.29578*atan2(aimag(z),real(z))
end function

